Smalltalk current createPackage: 'Easnoth-EventManagers' properties: #{}!
Object subclass: #EventManager
	instanceVariableNames: ''
	package: 'Easnoth-EventManagers'!

!EventManager methodsFor: 'not yet classified'!

test
^0
! !

EventManager subclass: #MapEditorEventManager
	instanceVariableNames: ''
	package: 'Easnoth-EventManagers'!

Object subclass: #HexMouse
	instanceVariableNames: ''
	package: 'Easnoth-EventManagers'!

!HexMouse methodsFor: 'not yet classified'!

mouseCoodToHexCoodX: x y: y
	"function that take mouse cood in pixel and return the coods of the tile selected"

	| xHex yHex cosmaingridx sinmaingridx cosmaingridy sinmaingridy cosothergridx sinothergridx cosothergridy sinothergridy nb nb2 nb3 nb4 nbCheck xConstante yConstante mapX mapY res |
	cosmaingridx := 0.882947593.
	sinmaingridx := 0.469471563.
	cosmaingridy := -0.130526192.
	sinmaingridy := 0.991444861.

	cosothergridx := 0.4539905.
	sinothergridx := 0.891006524.
	cosothergridy := -0.882947593.
	sinothergridy := 0.469471563.
                
	nb := ((y-(cosmaingridx/sinmaingridx)*x-(mapY+0)+(cosmaingridx/sinmaingridx)*(mapX+320))/(55*cosmaingridx)).
	nb2 := ((y-(cosmaingridy/sinmaingridy)*x-(mapY+480)+(cosmaingridy/sinmaingridy)*(mapX+206))/(173.2*cosmaingridy)).
	
	nb := nb truncated.
	nb2 := nb2 truncated.
	
	xConstante := 9 + nb mod: 3.
	yConstante := 20 + nb2 mod: 2.
	(nb2\\2 = 0) ifTrue:[yConstante := yConstante + ((nb+1) mod: 2)].
	
	xHex :=((xConstante-nb)/6)+((yConstante-nb2)/2).
	xHex := xHex truncated.
	yHex := ((nb-xConstante)/4)+((yConstante-nb2)/4).
	yHex := yHex truncated.
	
	(((nb mod: 6)=1) & ((nb2 \\ 2)=0)) ifTrue:[
		xHex := xHex + 1.
		(((nb2 \\ 4)=0) & (((nb mod: 12)=7) not)) ifTrue:[yHex := yHex + 1].
		(((nb2 mod: 4)=2) & ((nb mod: 12)=7)) ifTrue:[yHex := yHex + 1].
	].
	
	((nb \\ 3) = 0) ifTrue:[       
		((((nb2 \\ 2) = 0) & ((nb \\ 6)=0)) | (((nb2 mod: 2)=1) & ((nb mod: 6)=3))) ifTrue:[
			nb3 := ((y-(cosothergridx/sinothergridx)*x-(mapY+0)+(cosothergridx/sinothergridx)*(mapX+301))/(68*cosothergridx)).
			nb3 := nb3 truncated.
			nbCheck := 3 + (2 * yHex) +(xHex \\ 2).
			(nb3 = nbCheck) ifTrue:[yHex := yHex - 1].
		]
		ifFalse:[
			nb4 :=((y-(cosothergridy/sinothergridy)*x-(mapY+480)+(cosothergridy/sinothergridy)*(mapX+212.5))/(95.75*cosothergridy)).
			nb4 := nb4 truncated.
			nbCheck := 7 -((3*xHex/2) truncated) + yHex.
			(nb4 = nbCheck) ifTrue:[
				((xHex \\ 2) = 0) ifTrue:[yHex := yHex - 1].
				xHex := xHex + 1.
			].
		].
	].
	
	res := Array new: 2.
	res at: 1 put: xHex.
	res at: 2 put: yHex.
	
	^res
! !

!Number methodsFor: '*Easnoth-EventManagers'!

mod: mod
	"function that return n%mod - hack for negative numbers --- Ex : mod(-5,6) return 1 instead of -5.
	It counter a bug when algo used %6 to mean <do it 1 tile out of 6> and coods were negative"
	^((mod+(self \\ mod)) \\ mod)
! !

